﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>在线答题</title>
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

    <link rel="stylesheet" type="text/css" href="assets/css/css.css">
    <link rel="stylesheet" type="text/css" href="assets/css/reset.css">
    <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>

    <script type="text/javascript" src="assets/js/rem.js"></script>

</head>
<body>

<div class="topic">
    <div class="entrance-bottom">
        <div class="topic-frameli"></div>
        <div class="entrance-bottom-frame clearfix">
        </div>
        <div style="text-align:center;margin-bottom:50px;">
            <div id="timer"></div>
            <div class="entrance-bottom-frame-line-button-submit">
                <div id="next" class="entrance-bottom-frame-line-button-frame-submit">下一题</div>
            </div>
            <div class="entrance-bottom-frame-line-button-submit">
                <div id="handPapers" class="entrance-bottom-frame-line-button-frame-submit" onclick="handPapers();">交卷
                </div>
            </div>
        </div>
    </div>
</div>


<script src="assets/js/index.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var data1 = [];
    var theRequest = new Object();
    window.onload = function () {
        $.ajax({
            type: "POST",
            url: "http://127.0.0.1:8083/examSystem/web/getQuestions",
            data: null,
            dataType: 'json',
            success: function (result) {
                if (result.code == 0) {
                    data1 = result.data;
                    loadQuestions();
                }
            },
            error: function (error) {
                $.modal.alertWarning("获取模版数据失败");
            }
        });
        var url = location.search; //获取url中"?"符后的字串 ('?modFlag=business&role=1')
        if (url.indexOf("?") != -1) {
            var str = url.substr(1); //substr()方法返回从参数值开始到结束的字符串；
            var strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
            }
        }
    }
</script>
<script type="text/javascript">
    let maxtime = 60;
    let msg = "距离结束还有" + 12 + "分" + 0 + "秒";
    document.getElementById("timer").innerHTML = msg;
    --maxtime;

    function CountDown() {
        if (maxtime >= 0) {
            minutes = Math.floor(maxtime / 60);
            seconds = Math.floor(maxtime % 60);
            msg = "距离结束还有" + minutes + "分" + seconds + "秒";
            document.getElementById("timer").innerHTML = msg;
            --maxtime;
        } else {
            clearInterval(timer);
            submitPapers();
        }
    }

    timer = setInterval("CountDown()", 1000);

    function handPapers() {
        if (!confirm("确认交卷吗？")) {
            return;
        }
        submitPapers();
    }

    function submitPapers() {
        let papers = {"answers": answers, "phone": theRequest.phone, "surplusTime": maxtime};
        console.log(papers);
        $.ajax({
            type: "POST",
            url: "http://127.0.0.1:8083/examSystem/web/submitExam",
            data: JSON.stringify(papers),
            contentType: 'application/json',
            dataType: 'json',
            success: function (result) {
                if (result.code == 0) {
                    alert("交卷成功!");
                    window.location.href = "achievement.html?phone=" + theRequest.phone;
                } else {
                    alert(result.msg());
                }
            },
            error: function (error) {
            }
        });
    }
</script>
</body>
</html>